package com.lyluly.coursemgmt.webmodule.controller;

import com.lyluly.coursemgmt.servicemodule.iService.IStuAttendService;
import com.lyluly.coursemgmt.servicemodule.model.StuAttend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @version v1.0
 * @author clc
 */
@Controller
@RequestMapping("/stuAttends")
public class StuAttendController {
    @Autowired
    private IStuAttendService iStuAttendService;

    /**
     * 添加一条学生考勤记录
     * @param stuAttend 学生考勤记录实体类
     * @param response
     */
    @PostMapping
    public void addStuAttend(@RequestBody StuAttend stuAttend, HttpServletResponse response){
        iStuAttendService.addStuAttendRec(stuAttend);
    }

    /**
     * 根据记录ID修改一条学生考勤记录
     * @param stuAttend 学生考勤记录实体类
     * @param response
     */
    @PutMapping
    public void modifyStuAttend(@RequestBody StuAttend stuAttend, HttpServletResponse response){
        iStuAttendService.modifyStuAttend(stuAttend);
    }

    /**
     * 根据记录ID删除一条学生考勤记录
     * @param stuAttendId 学生考勤记录ID
     * @param response
     */
    @DeleteMapping("/{stuAttendId}")
    public void removeStuAttend(@PathVariable int stuAttendId, HttpServletResponse response){
        iStuAttendService.removeStuAttend(stuAttendId);
    }

    /**
     * 根据记录ID查找一条学生考勤记录
     * @param stuAttendId 学生考勤记录ID
     * @return 返回相应学生考勤记录
     */
    @GetMapping("/{stuAttendId}")
    @ResponseBody
    public StuAttend findStuAttendById(@PathVariable int stuAttendId){
        return iStuAttendService.findStuAttendById(stuAttendId);
    }

    /**
     * 查找所有学生考勤记录
     * @return 返回所有学生考勤记录
     */
    @GetMapping
    @ResponseBody
    public List<StuAttend> findStuAttendList(){
        return iStuAttendService.findStuAttendList();
    }

    /**
     * 根据学生ID查找若干条学生考勤记录
     * @param sId 学生ID
     * @return 返回相应学生考勤记录
     */
    @GetMapping("/sId/{sId}")
    @ResponseBody
    public List<StuAttend> findStuAttendListBySId(@PathVariable String sId){
        return iStuAttendService.findStuAttendListBySId(sId);
    }

    /**
     * 根据课堂ID查找若干条学生考勤记录
     * @param lessonId 课堂ID
     * @return 返回相应学生考勤记录
     */
    @GetMapping("/lessonId/{lessonId}")
    @ResponseBody
    public List<StuAttend> findAttndREcListByClassId(@PathVariable int lessonId){
        return iStuAttendService.findStuAttendListByClassId(lessonId);
    }

}
